Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

React Native "native" SDK - #4

Merged
benjackwhite merged 140 commits into
masterfrom
feat/multi-domain-support
Aug 2, 2022
Merged

benjackwhite merged 140 commits into
masterfrom
feat/multi-domain-support

Conversation

@benjackwhite

@benjackwhite benjackwhite commented Jul 12, 2022 •

Copy link
Copy Markdown
Collaborator

Note: Eventually this will be merged into posthog-js but for now it is here as in spirit it is trying to be a "lite" version of the RN library as well as a starting point for a unified JS core.

What do I want to actually release?

  • /examples/example-expo > An example Expo app showing how Posthog can be used without any native rebuilding
  • /posthog-core > The "core" package containing all non-platform specific code (interface, queueing logic etc.)
  • /posthog-react-native > The new RN SDK that uses the core as its base and adds new functionality as well as removing the dependency on native code (i.e. posthog-ios/android)
    • Features
    • No native dependencies needed
    • Autocapture - Touch events are tracked similar to the web with special React props detected ph-label as well as not-tracking with ph-no-capture
    • useLifecycleTracking > React hook to take care of correctly tracking events related to opening, backgrounding etc.
    • useNavigationTracker > Automatic Screen tracking of routes when using react-navigation/native with controls for customising the screen name or properties tracked
    • Feature flags
    • Groups
    • Sessions

What is more of an experiment

  • /posthog-web > Actually moving the posthog-js to this unified core is of course a massive undertaking. This is more of an example to show how it could work and to make sure the design of the core is not limiting a browser platform
  • /posthog-node > This is more realistic that we could migrate over to a shared core but is not fully functioning. Most crucial would be handling the fact that this SDK will be used for multiple "users" rather than one persisted user. Nonetheless it shows high-potential

Outstanding TODOs

  • ❌ Ideally, the new RN lib would work with the old one such that persisted data like distinct_id is re-used. I started on this for iOS but an Android workaround would be needed and this would need some way of testing it works
    • iOS should work but Android uses a completely non-expo supported way of storing data
  • Improve the build system - I'm using yarn workspaces (and yalc for the example app) but each package should be built with minified bundles, js, types etc. It's not perfect yet.
  • Get the package version from the package.json - couldn't get this to work without weird tsconfig issues
  • Ensure Opt out / in logic is working perhaps with persistence?
  • Enable retries
  • ❌ Ensure backwards compatible with current React Native library
    • Too many changes here. We can at least keep the overall API the same, but instantiation is simply different now
  • Feature flags
    • polling
    • subscribing
    • overriding
    • persisting to storage
    • adding to tracking events
  • Decide on the validation code. It was mostly copied from posthog-node and its questionable how useful it is.
  • Save the groups information properly to be used for feature flags
  • Persist the queued events to some sort of storage. Especially for mobile this is important as apps can be killed randomly.
  • Reset
  • Listener for events (feature flags, flush, queue)
  • Tests tests tests tests...
  • Unref timers for Nodejs?
  • React Native E2E tests (Detox could be an option)
  • CI / CD flows
  • This: https://github.com/PostHog/posthog-js/pull/404/files

Follow up

  • Detect network errors and either not flush or add back to queue
  • SessionID tracking
  • Mask autocapture fields that could be sensitive - all props
  • Pull out autocapture into a separate PR

Comment thread posthog-core/src/index.ts Resolved

@weyert weyert left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! I have might some suggestions that I saw while having a quick look :)

Comment thread posthog-core/src/eventemitter.ts Resolved
Comment thread posthog-core/src/index.ts Resolved
Comment thread posthog-core/src/index.ts Resolved
@weyert

weyert commented Jul 15, 2022

Copy link
Copy Markdown

Get the package version from the package.json - couldn't get this to work without weird tsconfig issues

You could use the version-hook of npm to update a file like version.ts, similar to:
https://github.com/open-telemetry/opentelemetry-js/blob/main/scripts/version-update.js

Or depending on the build tools you could also use something like https://github.com/google/semantic-release-replace-plugin

@benjackwhite
benjackwhite merged commit d5088cf into master Aug 2, 2022
@benjackwhite
benjackwhite deleted the feat/multi-domain-support branch August 2, 2022 09:33
@benjackwhite
benjackwhite restored the feat/multi-domain-support branch August 2, 2022 09:34
@benjackwhite
benjackwhite deleted the feat/multi-domain-support branch August 2, 2022 09:36
@coderabbitai coderabbitai Bot mentioned this pull request Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants